home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / gema26a / gema_eng.doc < prev    next >
Text File  |  1996-01-04  |  35KB  |  1,172 lines

  1.  
  2.                                  -(G)-(E)-(M)-(A)-
  3.                         [G]enPC [E]lite [M]acro [A]ssembler
  4.  
  5.                            (C)oderite SECTOR ONE 1994-95
  6.  
  7.                        English documentation for version 2.6
  8.  
  9.  
  10. I. Introduction
  11.     1. Shareware
  12.     2. Credits
  13.     3. Greetings
  14.  
  15. II. Generalities
  16.     1. Addressing modes
  17.     2. Arithmetic
  18.     3. Assembly directives
  19.  
  20. III. Mnemonics
  21.  
  22.  
  23. IV. Conclusion
  24.                                           --==--
  25.  
  26. I. Introduction
  27. _______________
  28.  
  29.  
  30.         GenPC aka GEMA is a new symbolic assembler for MS-DOS. It is
  31. mainly based upon the 68k reference : GenST on Atari ST. Moreover the logical
  32. structure of Motorola 680x0 was adapted to Intel mnemonics, as it is actually
  33. easier and more logical. Opposed to TASM that wants to get a lousy pseudo-
  34. structurated style and features lotsa bugs ( especially with 386+ instructions
  35. ), and doesn't let us really guess how our source codes will be assembled, GEMA
  36. let you enjoy heavy coding and was especially designed for 32-bit processing.
  37.         It now supports all the opcodes of Intel processors, from 8086 to P6,
  38. including all discovered, but undocumented opcodes !
  39.  
  40.     In addition, it is really faster than TASM, doesn't need any linker,
  41. and features handy assembly directives, especially INCBIN, that has always been
  42. missing on TASM and MASM.
  43.  
  44.     If you never coded in machine language before, GEMA is the tool you
  45. need to discover the marvellous ( well... just about ) world of 80x86. And
  46. you'll be easily able to learn 680x0 if you need to.
  47.  
  48.     If you already know the 680x0 joys, you won't have to worry about the
  49. lousiness of Intel stuff anymore and won't yell about the lameness of the
  50. classical assembly tools.
  51.  
  52.     If you're coding on 80x86, you must fed up with TASM and MASM. So that
  53. GEMA is the assembler you need ! It is especially designed for 32-bit coding
  54. ( protected or flat-real modes ) and is really easy to use in this context,
  55. opposed to the previous references.
  56.  
  57.     A full integrated environment with a powerful editor and debugger
  58. ( MonST-like ) are about to be released.
  59.  
  60.  
  61. I.1 Shareware
  62. -------------
  63.  
  64.  
  65.     GEMA is a SHAREWARE. Installing it on your hard disk implies your
  66. agreement to the following terms :
  67.  
  68.     - If you are working in a telco company, you have to clean up my
  69. phone-bills,
  70.  
  71.     - If you think the world of COBOL, you have to kill yourself,
  72.  
  73.     - If you're one of my teachers, you have to gimme good results to the
  74. exams and projects,
  75.  
  76.     - If you're a coder, graphixx-man, music-man, or courrier, love demos,
  77. and don't belong to any crew, you'd better join Sector One,
  78.  
  79.     - If you're a 20-years old female, you must fall in love with me,
  80.  
  81.     - If you can have cheap hardwares, let me know,
  82.  
  83.     - If you find bugs in GEMA, let me also know,
  84.  
  85.     - If you find none, it's because you never used it :) Bad boy,
  86.  
  87.     BTW, this is just a beta-release, it's why some bugs are maybe still
  88. present. Please report them to me by writing down what you exactly did, what
  89. happened, what sould have happened, and the version of your release.
  90.  
  91.     If you like to register as kewl official GEMA user, please send me a
  92. nice letter, telling what you're thinking about it. You can also help me coding
  93. a part of the complete assembly-package. Just ask for the source code and tell
  94. me what you'd like to do on it. You can also send me a few money, at least to
  95. cover the mail charges. The official registration fee was 50 FF or $10.00 .
  96.         If you do it :
  97.  
  98.     - You will have a good conscience,
  99.  
  100.     - You will support the author to improve GEMA and code other
  101. sharewares,
  102.  
  103.     - You will get all the new releases by e-mail or snail-mail,
  104.  
  105.     - Your name will be quoted in our greetings-list.
  106.  
  107.     I'd also enjoy receiving anything done with GEMA.
  108.  
  109.  
  110. I.2 Credits
  111. -----------
  112.  
  113.  
  114.     Assembler : design, documentation, coding ........... Jedi/Sector One
  115.     Moral support : .................................... Stephanie Mauger
  116.     Spelling correction of the french doc : ....................... Mogar
  117.     Used software : QEdit, Gema, Hacker's View, DJGPP
  118.     Beta-testing : MJS, Altomcat/Sector One, Oxygene, Keops/Equinox, Alexey
  119. Voinov
  120.  
  121.     You can get in touch with me at the following address :
  122.  
  123.         Frank DENIS
  124.         2, rue Madeleine Laffite
  125.         F-93100 MONTREUIL
  126.         FRANCE
  127.  
  128.         Or thru InterNet : j@nether.net
  129.  
  130.     Your can get the latest release by sending an e-mail titled
  131. "GET GEMA" to the previous address, or on ftp.nether.net in the directory :
  132. /pub/gema/* . You can also leech it without any ratio on ACE BBS
  133. +33-1-4588-7548 or thru FidoNet with "GEMA" as keyword on the node 2:320/305.
  134.  
  135.     But please, never phone to me...
  136.  
  137.  
  138. I.3 Greetings
  139. -------------
  140.  
  141.  
  142.     Dream regards to : Infiny ( LCA, Gandalf ), Eclipse ( Hacker Croll ),
  143. CyberPunk, Trash, Dream Syndicate, Underground Tectonics, EKO ( Maxx-Out,
  144. McDo, Createur, Jool ), Eagles ( Ard ), Equinox ( Keops, Checksum, Al Cool ),
  145. Lego System ( Skill ), Dune, Fantasy, Genesis, DBA ( Bonus Software ),
  146. Sentry ( Eagle ), Isiolis, Imphobia, Dead Hacker Society, Control Team,
  147. Quicky, Daniel Bozinov, Michel Furic, Live!, Fantasy, Anixter, Fongus,
  148. Bresil, DSK, Alexey Voinov, Oxygene, Jared, Impact Studios, Kloon, Antares,
  149. Pulse, RealTech, Animal Mine, Oxyron, Max in the Star System, Epsilon, EMF,
  150. Plant, Cascada, Cubic Team, and you !
  151.  
  152.  
  153. II. Generalites
  154. ---------------
  155.  
  156.  
  157.     GEMA works on 386, 486, Pentium or P6+. It takes one or two parameters
  158. that are the name of the source code and eventually the name of the executable
  159. file.
  160.  
  161.     eg : gema foo.s
  162.     or : gema foo.s bar.exe
  163.  
  164.     If the second parameter is missing, the name of the executable file
  165. will be the name of the source with a COM or EXE suffix.
  166.  
  167.         Some options may prefix the file names :
  168.  
  169.         -E or --preprocess : display each processed line
  170.         -v or --verbose    : verbose output
  171.         -q or --quiet      : reduced output
  172.         -o or --optimize   : extended automatic optimizations ( 3 passes )
  173.         -nw or --nowarning : disable warnings
  174.         -a or --autoalign  : enable automatic alignment ( experimental )
  175.         -86, -88, --cpu=86 or --cpu=88,
  176.         -186 or --cpu=186,
  177.         -286 or --cpu=286,
  178.         -386 or --cpu=386,
  179.         -486 or --cpu=486,
  180.         -586, -pentium, --cpu=586 or --cpu=pentium,
  181.         -686, -p6, --cpu=686 or --cpu=p6 : assemble only the opcodes supported
  182. by the designed kind of processor. By default, all instructions from 8086 to
  183. p6 are supported.
  184.  
  185.  
  186. II.1 Addressing modes
  187. ---------------------
  188.  
  189.  
  190.     All addressing modes conforms to the Motorola 680x0 format, ie :
  191.  
  192.     Designation             Intel                   GEMA
  193.     ------------------------------------------------------------------
  194.     Short immediate         12                      #12.b
  195.     Immediate (word)        32000                   #32000.w
  196.     Immediate (long word)   99999                   #99999.l
  197.  
  198.  
  199.     .b, .w and .l are optional. They allow forcing a type, for instance
  200. to cast a value that fits into one byte as a long world. This can be quite
  201. useful with self-modifying code. If the size isn't explicitely fixed, GEMA
  202. finds automatically the smallest one.
  203.  
  204.  
  205.     Designation             Intel                   GEMA
  206.     ------------------------------------------------------------------
  207.     Direct                  AH, BX, ECX, SI, CS     AH, BX, CE, SI, CS
  208.  
  209.  
  210.     Under GEMA, the registers are designed the same way than TASM,
  211. excepted for 32-bit registers that looks like : AE, BE, CE, DE, SIE, DIE, BPE
  212. and SPE, as it's more logical. But in most cases, just one letter ( A, B, C or
  213. D ) is enough. Indeed, like 680x0, the size of operands is explicitely part of
  214. the instruction and GEMA sets them automatically.
  215.  
  216.     So that : NEG.B A under GEMA means NEG AL with TASM.
  217.  
  218.     By default, a ".B" instruction applied to a single-letter register is
  219. interpreted as AL, BL, CL or DL. To mention AH, BH, CH or DH, just write the
  220. full designation. For instance : NEG.B AH
  221.  
  222.         NEG.W A under GEMA means NEG AX with TASM
  223.  
  224.     Excepted for instructions that don't deal with words as operands, the
  225. default size of all mnemonics is the word. So that NEG.W A and NEG A have the
  226. same effects. So do most of the instructions.
  227.  
  228.         NEG.L A under GEMA means NEG EAX with TASM
  229.  
  230.     We can always use the full designation of a register instead of a
  231. single-letter shorthand. For instance, NEG.L EAX is okay. But NEG.L AX will
  232. ware as the operand size is incoherent with the instruction size.
  233.  
  234.     If you ever think this is harder to design explicitely the size in the
  235. mnemonic instead of an implicit guess based upon operand sizes, you understood
  236. nothing to life. 'Coz it's actually clearer like this and you don't have to
  237. add gadgets like WORD PTR in ambiguous cases.
  238.  
  239.     So that : NEG.L (SI,DI) under GEMA means NEG DWORD PTR [SI][DI] with
  240. TASM.
  241.  
  242.     Oh BTW, I was about to forget it... You can always use ".s" instead of
  243. ".b" if you prefer... This was just designed to keep on the norms of GenST.
  244.  
  245.  
  246.     Designation                     Intel                   GEMA
  247.     ------------------------------------------------------------------
  248.     Short absolute                  [12]                    12.b
  249.     Absolute (word)                 [32000]                 32000.w
  250.     Absolute (long)                 [99999]                 99999.l
  251.  
  252.  
  253.     Once again, the ".b", ".w" and ".l" are optional. They could be
  254. useful only to cast a type. Otherwise, the assembler guess them on its own.
  255.     Under GEMA, like in 680x0, and as an immediate value would be
  256. prefixed ( with a "#" ), an absolute address has no prefix. It's also the way
  257. with labels :
  258.  
  259.  
  260.         NEG label under GEMA means NEG WORD PTR [label] with TASM
  261.  
  262.  
  263.  
  264.     Designation                     Intel                   GEMA
  265.     ------------------------------------------------------------------
  266.     Indirect                        [SI]                  (SI)
  267.     Indirect with register          [SI+BX]               (SI,BX) or (SI,B)
  268.  
  269.  
  270.     The default size for an index register is a word.
  271.  
  272.  
  273.     Designation                     Intel                   GEMA
  274.     ------------------------------------------------------------------
  275.     Indirect with reg and offset.b  [SI+BX+12]             12.b(SI,BX)
  276.     Indirect with reg and offset.w  [SI+BX+32000]          32000.w(SI,BX)
  277.     Indirect with reg and offset.l  [ESI+EBX+99999]        99999.l(SIE,BE)
  278.  
  279.  
  280.     As expected, ".b", ".w" and ".l" are optional, they're only useful
  281. as casts. For instance 12(SI,BX) is exactly equivalent to 12.b(SI,BX). Most of
  282. the time, there's no good adding these suffixes. Offsets can be set as they
  283. are, GEMA will find a way outta difficulties.
  284.  
  285.  
  286.     Designation                     Intel                   GEMA
  287.     ------------------------------------------------------------------
  288.     Indirect reg/off/factor         [ESI+EBX*factor+off]  off(SIE,BE*factor)
  289.  
  290.  
  291.     Once again, offsets can be bytes, words or long words. BTW, a factor
  292. can be applied only to 32-bit registers, as well as long offsets ( someone
  293. told me that was a bug of GEMA, but this is not : this is the tricky Intel
  294. architecture ) .
  295.  
  296.     THE *SOURCE* ARGUMENT IS ALWAYS THE *FIRST* ONE AND AN OPTIONAL TARGET
  297. ARGUMENT, ALWAYS THE NEXT ONE.
  298.  
  299.     This is nothing but the intelligent Motorola logic.
  300.  
  301.     So that with GEMA, to copy the value of AX into BX, just write :
  302.  
  303.  
  304.     MOVE A,B ( or MOV A,B )
  305.  
  306.  
  307.     ... and not MOV B,A as TASM would expect it.
  308.  
  309.     Of course, instructions like ENTER that don't manage source and
  310. destination arguments, have no reason to get reversed arguments. But for the
  311. rest, the Motorola syntax has to be used.
  312.  
  313.  
  314. II.2 Arithmetic
  315. ---------------
  316.  
  317.  
  318.     All classical operators are available for offsets and immediate values.
  319.     Here is the decrescent list :
  320.  
  321.     []: These are the parenthesis
  322.     - : Opposite to a number
  323.     < : Left shift. For instance : 3<2 sends back 12
  324.     > : Right shift. 6>1 sends back 2
  325.     ^ : Exclusive OR
  326.     & : Logical AND
  327.     | : Logical OR
  328.     / : Divide
  329.     * : Multiply
  330.     - : Sub
  331.     + : Add
  332.     % : Modulo
  333.     = : Equal : sends back 0 if the expression is false, 1 otherwise
  334.     @ : Divide by 16 what follows. For instance, @fooLabel sends the
  335. segment address of the label Toto, according to the current ASSUME value. This
  336. operator is accumulable, for instance @@fooLabel divide fooLabel by 256. But
  337. it's just an arithmetic operation, there will be no relocation ( see \ above ) .
  338.     ~ : Logical NOT
  339.     \ : Sends back the segment address of what follows. This forces the
  340. result of the expression to a word and will be relocated is the executable code
  341. is a .EXE . It's a kinda SEG prefix like with MASM and TASM.
  342.     : : ( Yes it's the ':' character )
  343.         Versions < 2.5 : returns the 4 lower bits of what follows,
  344.         Versions >=2.5 : returns what follows modulo the current segment
  345. size. Was changed for compatibility purpose with A2G. In practice, this is
  346. quite a dummy operator...
  347.  
  348.     Stupid but funny instance : 2+3*4/[-5-7]<[~3^5]
  349.  
  350.     Apart from numbers, lotsa other things may be used inside arithmetic
  351. operations :
  352.  
  353.     * : Asterisks mean the address of the current instruction, or to be
  354. more precize, its offset to the beginning of the program.
  355.  
  356.  
  357.     For instance :      bra.s *
  358.           equals : foo  jmp foo
  359.  
  360.  
  361.     '': ASCII values of one or more characters.
  362.  
  363.  
  364.     For instance : 'A' equals 65
  365.                   'AB' equals $4142
  366.  
  367.  
  368.     Bases :
  369.     -------
  370.  
  371.     A raw number is parsed as decimal by default. Even if there are one or
  372. more zeros at the beginning.
  373.  
  374.     Hexadecimal numbers have just to be prefixed by a '$' ( how silly is
  375. the 'h' suffix with sometimes a '0' suffix to avoid confusions ! )
  376.  
  377.  
  378.     For instance : $ABCD1234 under GEMA means 0ABCD1234h with TASM
  379.  
  380.  
  381.     A binary constant has to be prefixed by a '%'.
  382.  
  383.  
  384.     For instance : %101 means 5
  385.  
  386.  
  387.     An octal number has to begin with the 'º' sign.
  388.  
  389.     Of course, arithmetic operations can mix several bases. And casting
  390. is always possible on all the expression...
  391.  
  392.  
  393.     For instance : [1+$12A/%10001001].b
  394.  
  395.  
  396.     ...But can also always be done on some terms of an expression :
  397.  
  398.  
  399.     For instance : $1234.b+1 means $35 ans not $1235 because the ".b"
  400. reduced the result to a single byte.
  401.  
  402.     So can GEMA evaluate complex expressions mixing different bases with
  403. type casts. Results can be used anywhere as constants, offsets or immediates.
  404.     But GEMA can also process these operations on symbols.
  405.  
  406.  
  407.     Symbols :
  408.     ---------
  409.  
  410.     There are 3 sorts of symbols :
  411.  
  412.     - Labels
  413.           ------
  414.  
  415.     The global format of an instruction line under GEMA is :
  416.  
  417.  
  418. [Label[:]]    [Mnemonic]    [Arguments]    [;] [Comments]
  419.  
  420.  
  421.     A label has to be always at the beginning of a line ( without any
  422. trailling space ) . So that the classical leading column is now optional.
  423.  
  424.     A mnemonic has not to be directly at the beginning of a line. Spaces
  425. or tabs must prefix it to avoid it being interpreted as a label. Reserved
  426. keywords can always be used as label names, this is not ambiguous.
  427.  
  428.     The comments don't need a semicolumn. But avoid this kinda comments
  429. as it overloads the source code that becomes less readable. And the heavy
  430. parsing technic used by GEMA has sometimes problems to distinguish comments
  431. and arguments. But don't panic, in all cases, you'll just get an error message,
  432. and never an unexpected result.
  433.  
  434.     A complete line of comments has to begin with a '*', ';', '%' or '/' .
  435.  
  436.  
  437.     For instance :
  438.  
  439.  
  440. foo    move.l a,b        this is a comment
  441.     addx (si,bx),c
  442. bar
  443.     bra.s foo
  444.  
  445. * dummy line
  446. / Another line of comments
  447.  
  448. junk:    nop
  449.  
  450.  
  451.         Usually, the semicolumn is not necessary to distinguish instructions
  452. and comments. But let you see the following case :
  453.  
  454.  
  455.         rts     returns to the main routine
  456.  
  457.  
  458.  
  459.         rts can be used without any argument or with a number corresponding to
  460. an extra depth of the stack. It's why GEMA will think "returns" is that depth
  461. ( being a label ) and "to the main routine" is a comment. To avoid this, just
  462. add a semicolumn :
  463.  
  464.  
  465.         rts     ; returns to the main routine
  466.  
  467.  
  468.         And there will be no possible confusion anymore. Thanks to Altomcat for
  469. having related that problem to me. In case of doubt you can add semicolumns
  470. all the time, this will be ok.
  471.  
  472.  
  473.  
  474.     You can also add extra spaces everywhere, GEMA will ignore them.
  475.  
  476.  
  477.     For instance :
  478.  
  479.     addx.l 4 + 3 / [ 1 + 2 ] (   sie   ,   be  *  8   )  ,  d
  480.  
  481.  
  482.     But never insert spaces between a mnemonic and its optional size
  483. indicator ( "addx.l" is ok, not "addx .  l" ) .
  484.  
  485.     The START label is always defined as a null label, ie. the beginning
  486. of the program and can be used by pedants the same way than NULL in C language.
  487.  
  488.     A label can be used inside an arithmetic expression. In this case, it
  489. represents the offset to the beginning of the program, less the ASSUME value
  490. ( see ASSUME above ) + the last ORG value ( see ORG above ) .
  491.  
  492.  
  493.     For instance :
  494.  
  495. foo    move.l #[foo-bar]/2,foo+2
  496.     ...
  497. bar    flush
  498.  
  499.  
  500.     Such labels can be defined only once a source code, otherwise would
  501. GEMA produce a redeclaration error. They have a constant value for the whole
  502. assembly, opposed to local labels and variables.
  503.  
  504.  
  505.     - Local labels
  506.       ------------
  507.  
  508.     Idem to global labels, excepted the fact they can be redefined. Their
  509. name have to begin with a dot. It's a pretty handy feature for loops.
  510.  
  511.  
  512.     For instance :
  513.  
  514.     move #$1234,c
  515. .wait    dec.c
  516.     bne.s .wait        bne = jnz
  517.  
  518.     ... some other piece of code ...
  519.  
  520.     move a,c
  521. .wait    nop
  522.     cmps.b
  523.     dbeq .wait        dbeq = loopnz
  524.  
  525.  
  526.     Local labels can be used in arithmetic expressions and equals the last
  527. point of their definition.
  528.  
  529.     They can even be set to any value with the SET directive and act like
  530. real numeric constants or counters.
  531.  
  532.  
  533.     For instance :
  534.  
  535. .wait    set $1234
  536.  
  537.     Oh yeah, that local label has now the $1234 value. But before being
  538. assigned a constant value, it is assigned the instruction offset like any other
  539. label. So what, would you say ? Yup, just try for instance :
  540.  
  541.  
  542. .wait    set .wait+2
  543.  
  544.  
  545.     As much as you do that, .wait will always be evaluated as two more
  546. bytes than its last declaration. IMHO, it's really useful for self-modified
  547. code.
  548.  
  549.     But now, let us imagine another situation, where you have to build a
  550. table of the 3 multiples. We'll explain later than the REPT...ENDR structure
  551. allows repeating a piece of source code several times and that DC.L is used to
  552. insert a constant long word ( like DD with TASM ) . What would be interesting
  553. in this case, would be that .wait equals optionally the offset value it was
  554. declared in the first time, and then that it would be only depending of the
  555. SET value for the other times.
  556.  
  557.     Of course, GEMA manages it with "assembly variables".
  558.  
  559.  
  560.     - Assembly variables
  561.       ------------------
  562.  
  563.     Their names begin with a '!'. They can be used as traditionnal labels.
  564. They are in fact local labels that are affected by the offset they stand in
  565. only the first time they're assigned. So here is the way we can build our table
  566. of multiples ( 0, 3, 6, 9, ... 255*3 ) :
  567.  
  568.  
  569. !foo    set 0
  570.     rept 256
  571.       dc.l !foo
  572. !foo      set !foo+3
  573.     endr
  574.  
  575.  
  576.     Marvellous, isn't it ? Any arithmetic expression can mix these 3 sorts
  577. of symbols and can even cast them to any type.
  578.  
  579.     Reserved keywords are supported, and there is no limit on significative
  580. length. Upper and lower cases are differencied. Allowed character for a label
  581. name are alphanumerics ( of course with no digit as a first character ),
  582. underscore, '!' and '.' .
  583.  
  584.  
  585. II.3 Assembly directives
  586. ------------------------
  587.  
  588.  
  589.     They have to be positionned to the second position, like mnemonics.
  590.  
  591.  
  592.     - REPT <constant> ... ENDR
  593.       ------------------------
  594.  
  595.     Repeat <constant> times a piece of code.
  596.  
  597.  
  598.     For instance :
  599.  
  600.     rept 5
  601.       nop
  602.           xlat
  603.         endr
  604.  
  605.     will produce : nop xlat nop xlat nop xlat nop xlat nop xlat
  606.  
  607.  
  608.     - SET
  609.       ---
  610.  
  611.     See the previous part.
  612.  
  613.  
  614.     - ORG <constant>
  615.       --------------
  616.  
  617.     Set the base offset. Exactly like equivalents on all other assemblers,
  618. excepted the fact that GEMA supports more than one, and anywhere in a program
  619. ( even though it is interesting only at the beginning ) .
  620.  
  621.  
  622.     For instance :
  623.  
  624.     org $100
  625.  
  626.  
  627.     GEMA will also agree with org #$100
  628.  
  629.  
  630.     - TITLE <title>
  631.       -------------
  632.  
  633.     Gives a title to the current source. Yet unused.
  634.  
  635.  
  636.     _ INCLUDE <file>
  637.       --------------
  638.  
  639.     Merge the file at this point of the current source and continue the
  640. assembly procedure ( like #include in C ) . Any source can include another one
  641. that may include other ones that may... There is no depth limit, but a basic
  642. check for circular references is done. The file name can be quoted or double-
  643. quoted ( or not quoted at all ) .
  644.  
  645.  
  646.     - USE16
  647.       -----
  648.  
  649.     Assume that the following code will be in a 16-bit code segment    by
  650. default ( ie. needs prefixes for 32-bit accesses ). Enabled by default.
  651.  
  652.  
  653.     - USE32
  654.       -----
  655.  
  656.     Assume that the following code will be in a 32-bit code segment by
  657. default. This is only possible in protected mode, and needed by most of the
  658. DOS-Extenders ( like PMODE ) .
  659.  
  660.  
  661.     - OPT
  662.       ---
  663.  
  664.     Enable or disable several options. Overrides command line options.
  665.  
  666.         OPT o+ : enable automatic optimizations
  667.         OPT o- : disable them ( default )
  668.         OPT w+ : enable all warnings ( default )
  669.         OPT w- : disable them
  670.         OPT v+ : verbose mode
  671.         OPT v- : normal mode ( default )
  672.         OPT q+ : quiet mode
  673.         OPT q- : normal mode ( default )
  674.         OPT a+ : enable automatic alignment
  675.         OPT a- : disable automatic alignment ( default )
  676.  
  677.         - ONCE
  678.           ----
  679.  
  680.         Like #pragma once implemented in most C compilers. Don't include the
  681. file if it was already included before.
  682.  
  683.  
  684.     - INCBIN <file>
  685.       -------------
  686.  
  687.     Here comes THE missing directive on TASM and MASM. It allows you to
  688. insert any BINARY file in the executable code. Forget lousy hexadecimal
  689. conversions or tiny files loading. To insert the picture of your girlfriend at
  690. the "tut" label, you now just have to do :
  691.  
  692.  
  693. tut    incbin cindy.jpg
  694.  
  695.         or
  696.  
  697. tut    incbin "cindy.jpg"
  698.  
  699.  
  700.     - DC
  701.       --
  702.  
  703.     Inserts a byte, a word, a long word or a string.
  704.  
  705.  
  706.     For instance :
  707.  
  708.     dc.b 1,2,3,4,"Tototata",'t',10
  709.     dc.w $1234,"tuttut",4
  710.  
  711.     In the last example, "tuttut" is inserted as single bytes as if we had
  712. done :
  713.  
  714.     dc.w $1234
  715.     dc.b "tuttu"
  716.     dc.w 4
  717.  
  718.  
  719.     - DS
  720.       --
  721.  
  722.     Inserts several nul bytes.
  723.  
  724.  
  725.     For instance :
  726.  
  727.     ds.b 4        means dc.b 0,0,0,0
  728.     ds.l 3        means dc.l 0,0,0
  729.  
  730.  
  731.     - EVEN, ALIGN, SEGMENT, PAGE, DPAGE, PPAGE
  732.       ----------------------------------------
  733.  
  734.     Inserts several nops so that the next instruction will be aligned.
  735.  
  736.     EVEN = 2 bytes
  737.     ALIGN.B / .W / .L / .Q = Try and guess ( .Q = Quand, .B is just here
  738. for fun ! )
  739.     SEGMENT = 16 bytes
  740.     PAGE = 256 bytes
  741.     DPAGE = 512 bytes
  742.     PPAGE = 2048 bytes
  743.  
  744.  
  745.     - MIN or MINI <xxx>
  746.       -----------------
  747.  
  748.     Minimal size your program need ( .EXE files only ) in 16-byte chunks.
  749.     Default is the size of your program.
  750.  
  751.  
  752.     - MAX or LIMIT <xxx>
  753.       ------------------
  754.  
  755.     Fix the maximal memory size your program has to reserve when loaded,
  756. in 16-byte chunks. Useful for overlays and resident programs.
  757.  
  758.  
  759.     - OVERLAY <xxx>
  760.       -------------
  761.  
  762.     Set an overlay ID.
  763.  
  764.  
  765.     - HEADER
  766.       ------
  767.  
  768.     Inserts the traditionnal header of a .EXE file, with the relocation
  769. table and all that stuff. It's usually the first instruction of a .EXE program.
  770. But GEMA allows you to put ones everywhere you want ( might be useful for self-
  771. extracting archives or nested executables ) .
  772.  
  773.  
  774.     - STACK
  775.       -----
  776.  
  777.     Describe where the initial stack ( SS:SP ) will be allowed when a .EXE
  778. file will be launched. All .EXE files should have a STACK.
  779.  
  780.  
  781.     For instance :
  782.  
  783.     header
  784.  
  785. * lotsa code
  786.  
  787.     ds.l 256
  788. * 256*4 bytes for the stack, that's enough !
  789.     stack
  790.  
  791. * other code or datas
  792.  
  793.  
  794.     - ASSUME
  795.       ------
  796.  
  797.     Fix the reference to compute the next label offsets inside arithmetic
  798. expressions. TASM allows this directive having different values for all segment
  799. registers. Well... IMHO there is no good doing that as we sould be able to do
  800. anything we need with our segment pointers, but maybe this feature will be
  801. implemented in the next releases of GEMA if requested by enough people.
  802.  
  803.  
  804.     - FATAL
  805.       -----
  806.  
  807.     Stop assemblying.
  808.  
  809.     - SECTION BSS or BSS
  810.       ------------------
  811.  
  812.     What follows will be "passively" assembled : the inline labels will
  813. be computed but no code will be integrated in the executable file. Usually
  814. used with "ds" at the end of a program.
  815.  
  816.     - SECTION TEXT or SECTION DATA or TEXT or DATA
  817.       --------------------------------------------
  818.  
  819.     Cancel the effects of the previous directives.
  820.  
  821.         - REAL or REALMODE
  822.           ----------------
  823.  
  824.         Assume that next segments ( from where one of these directives is, and
  825. after SEGMENT, PAGE, DPAGE or PPAGE ) are 64 Kb long like in real-mode. These
  826. directives are only useful to produce an error in case of overflow. They have
  827. no consequence on code generation.
  828.  
  829.         - UNREAL or UNLIMIT or FLAT
  830.           -------------------------
  831.  
  832.         Opposed to the previous directives, this set assume that the next
  833. segments ( until a new directive of this kind is encountered ) have no size
  834. limit. By default, all segments have an infinite size for GEMA.
  835.  
  836.         - SEGSIZE <size>
  837.           --------------
  838.  
  839.         The following segments will be <size> bytes long.
  840.  
  841.  
  842.         These three sets of directives may be prefixed with an alignement
  843. directive ( SEGMENT, PAGE, DPAGE or PPAGE ) or can be themselves prefixes to
  844. any instruction.
  845.  
  846.         For instance :
  847.  
  848.                 SEGMENT:REAL
  849.  
  850.         is exactly like :
  851.  
  852.                         SEGMENT
  853.                         REAL
  854.  
  855.  
  856.                 SEGSIZE 4096:PAGE
  857.  
  858.         means :
  859.  
  860.                         SEGSIZE 4096
  861.                         PAGE
  862.  
  863.         In both cases, the order has no influence. So that DPAGE:UNREAL and
  864. UNREAL:DPAGE have the same meaning.
  865.  
  866.         Theses directives are usually useful in real mode or in protected mode
  867. with funny segment sizes. In all other cases, there is no good using them, as
  868. GEMA assume all segments are infinite by default.
  869.  
  870.  
  871. III. Mnemonics
  872. --------------
  873.  
  874.  
  875.     All ( but two ) TASM and MASM mnemonics are available with the same
  876. designation under GEMA, even all synonyms ( such as JZ and JE ) . Some
  877. mnemonics have different names with TASM and MASM ( for instance XLAT and
  878. XLATB ) : both designations are supported by GEMA and have of course the same
  879. effect.
  880.  
  881.     But GEMA also features alternative synonyms. Most of them are 680x0
  882. equivalents or more logical forms.
  883.  
  884.     The following list represents some equivalent mnemonics and those that
  885. need some extra comments :
  886.  
  887.     LEAVE = UNLINK
  888.     MOV = MOVE
  889.     MOVSX = MOVESX
  890.     MOVZX = MOVEZX
  891.     TRAPV = INTO
  892.     WBINVD = FLUSH
  893.     TRAP = INT
  894.  
  895.     TRAP supports an abolute way of writing its argument.
  896.  
  897.  
  898.     For instance, TRAP #14 is exactly identical to TRAP 14 or INT 14.
  899.  
  900.  
  901.     RTED = RTID = IRETD
  902.     RTE = RTI = IRET
  903.     BRAF ~ JMPF
  904.  
  905.     JMPF is the FAR alternative of JMP. It is waiting for two arguments
  906. that are the segment and the offset, for instance JMPF $14c9,$418db2a.
  907.     But as we often use a FAR JMP with a label address or an absolute
  908. address, writing "JMPF \label,:label" all the time would be actually lousy.
  909.     Instead, just use BRAF, that works similar to JMPF excepted the fact
  910. it expects only one argument, a 32-bit address that it automatically converts
  911. to a segment and an offset.
  912.  
  913.  
  914.     For instance, BRAF $12345 is similar to JMPF $1234,5
  915.  
  916.  
  917.     386+ allow use of these instructions with a 32-bit offset.
  918.  
  919.  
  920.     BRA ~ JMP
  921.  
  922.     BRA is similar to JMP excepted the fact that, as expected, JMP label
  923. under GEMA means JMP [label] to TASM, ie. a jump to the address contained in
  924. "label", and not a direct jump to "label". It's why a logical way of doing
  925. this is JMP #label. But as "JMP #label" are often more useful than "JMP label",
  926. you'd rather use BRA, that is similar excepted in this case. "BRA label" means
  927. "BRA #label" or "JMP #label". In other cases, BRA can deal with all the
  928. addressing modes a JMP would support, such as "BRA (si, dx)". A BRA or JMP can
  929. be short, word or long ( for flat-real and protected modes ) .
  930.  
  931.  
  932.     REP = REPE = REPZ
  933.  
  934.  
  935.     There are two way of using these prefixes :
  936.  
  937.         - Either as independant instructions on a single line, keeping
  938. all the features of any instruction,
  939.  
  940.         - Or as prefixes. In this case, as any good prefix, they have
  941. to be placed before the instruction they act on. A column must separe both
  942. elements.
  943.  
  944.  
  945.     For instance :
  946.  
  947. toto    ds
  948.     gs: move.l (si),a
  949.     rep   : outs.b
  950.     repne
  951.     ins.l
  952.  
  953.     As you can see, you can add extra spaces before and after the column
  954. without any problem, as always.
  955.  
  956.  
  957.     HLT = STOP
  958.     XOR = EOR
  959.     CMC = NGC
  960.     CLD = D+    ( '+' means : increment )
  961.         STD = D-        ( '-' means : decrement )
  962.     CLI = INTOFF
  963.     STI = INTON    ( Saturn coders will love these ! )
  964.     ADDX = ADC
  965.     BS+ = BSF    ( idem, IMHO, a '+' is clearer than (F)orward )
  966.     BS- != BSR
  967.  
  968.     WARNING : BSR HAS NOT THE SAME MEANING UNDER GEMA AND UNDER TASM&MASM.
  969.  
  970.     Indeed, it is used to call subroutines as we'll explain it later. So
  971. that to scan bits in reversed mode, you MUST use BS-.
  972.  
  973.     BTSTC = BTSTN = BTC
  974.     BTSTR = BTR
  975.     TAS = BTS = BTSTS
  976.     BTST = BT
  977.     (BSRF = JSRF) ~ CALLF
  978.  
  979.     There are the FAR version of CALL. The way is the same as JMPF and BRAF
  980. but the instructions that only expect one argument are BSRF and JSRF. The CALL
  981. instruction as we always knew it is logically named CALLF.
  982.  
  983.     It is absolutely RIDICULOUS declaring subroutines with PROC NEAR or FAR
  984. foo in machine language. Assembly was designed for heavy coders wanting to make
  985. their compi blow out their silicon minds and not structured-languages fans that
  986. would better have to try PASCAL or another shit like that.
  987.     So that under GEMA, you just have to do a BSRF or BSR, and you know
  988. exactly how it will be assembled.
  989.  
  990.  
  991.     (BSR = JSR) ~ CALL
  992.  
  993.  
  994.     NEAR version of CALL. See BRA and JMP.
  995.  
  996.  
  997.     RTS = RTN
  998.     RTSF = RTNF
  999.  
  1000.  
  1001.     NEAR and FAR ways of coming back from a subroutine. May be followed by
  1002. an immediate to enforce the stack depth.
  1003.  
  1004.  
  1005.     EXTA.Q = EXT.Q = CDQ
  1006.     EXTA = EXT or EXT.W = CBW
  1007.     CWD = EXT.L = EXTA.L
  1008.     DIVS = IDIV
  1009.     DIVU = DIV
  1010.     LINK = ENTER
  1011.     WAIT = FWAIT ( Microsoft / Borland )
  1012.     MULS = IMUL
  1013.     MULU = MUL
  1014.     INS, OUTS, MOVES, LODS and co. :
  1015.  
  1016.  
  1017.     The string concerns have to follow the GEMA's logic, that is an
  1018. instruction optionally followed by its size, being .W by default.
  1019.     So that instead of OUTSD with TASM, just write : OUTS.L
  1020.  
  1021.  
  1022.     BHI = JNBE
  1023.     BCC = JAE = JNB = JNC
  1024.     BCS = JNAE
  1025.     BLS = JBE = JNA
  1026.     BGE = JGE = JNL
  1027.     BVC = JNO
  1028.     BLT = JNGE
  1029.     BLE = JLE = JNG
  1030.     BCXZ = JCXZ
  1031.     BEQ = JE = JZ
  1032.     BGT = JNLE
  1033.     BECXZ = JECXZ = JCEZ = BCEZ
  1034.     BPL = JNS
  1035.     BNE = JNE = JNZ
  1036.     BPO = JPO = JNP
  1037.     BVS = JO
  1038.     BPE = JPE = JP
  1039.     BMI = JS
  1040.  
  1041.  
  1042.     I maybe forgot some, but are equivalent :
  1043.  
  1044.         - All synonyms recognized by MASM and TASM
  1045.         - Their Motorola 680x0 equivalent
  1046.  
  1047.  
  1048.     SETxx = Sxx
  1049.  
  1050.  
  1051.     Idem. For instance, SZ can be used as well as SEQ ... All Microsoft,
  1052. Borland and Motorola ways are recognized.
  1053.  
  1054.  
  1055.     LOOPE = LOOPZ = DBEQ
  1056.     LOOPNE = LOOPNZ = DBNE
  1057.     LOOP = DBF = DBRA
  1058.     ROXL = RCL
  1059.     ROXR = RCR
  1060.     SAHF = SAF
  1061.     ASL = SAL = SHL
  1062.     ASR = SAR ( != SHR )
  1063.     SUBX = SBB
  1064.     XLAT = XLATB
  1065.  
  1066.  
  1067.     Of course, whatever synonym you choose, the addressing modes keeps the
  1068. GEMA's norm.
  1069.         - When an immediate value is always awaited, removing the '#'
  1070. is tolered,
  1071.  
  1072.         - When the register size depends from the instruction size
  1073. ( 95% of the usual cases ), you can use one-letter designations for registers,
  1074.  
  1075.         - When a source and target arguments are involved, they have to
  1076. be always in this order,
  1077.  
  1078.         - Instructions featuring a 32-bit alternative should active it
  1079. with ".L" or it is automatically done with 32-bit offets or immediates.
  1080.  
  1081.     Anyway, when there is no possible ambiguousness, GEMA tolers some
  1082. abuses ( like INT 14 that normally should be only INT #14 ), and in all cases,
  1083. the most logic way is assumed. And in case of trouble, lotsa pretty precize
  1084. errors and warnings will help you.
  1085.  
  1086.  
  1087.         AAM and AAD
  1088.  
  1089.         These instructions may be followed by an immediate number ( with or
  1090. without a # ) and allow any divisor ( and not only 10 ) . This works on all
  1091. CPU, but was never officially documented.
  1092.  
  1093.         SALC
  1094.         ICEBP = ICE01 = TRAP01
  1095.         UMOV = UMOVE
  1096.         LOADALL
  1097.  
  1098.         Undocumented opcodes of 386+. See www.x86.org for more informations.
  1099.         All these opcodes are implemented in GEMA, but a warning appears when
  1100. the verbose ( -v or --verbose ) option is enabled.
  1101.  
  1102.         CMOV = CMOVE
  1103.         RDPMC
  1104.         UD
  1105.         UD2
  1106.  
  1107.         New opcodes of the P6 CPU, fully implemented in GEMA. As UD and UD2
  1108. seem to be working on other sort of CPU, too, they never generate any warning.
  1109.  
  1110.  
  1111.  
  1112.  
  1113.     Here is a very complex and original program, displaying "Hello World"
  1114. on your screen :
  1115.  
  1116.     org $100
  1117.  
  1118.         push cs
  1119.         pop ds                          ds = cs
  1120.         move #plouf,d                   plouf's offets in dx
  1121.         move.b #9,ah                    9 in ah
  1122.         trap #$21                       system call #$21
  1123.         move #$4c00,a                   exit(0)
  1124.         trap #$21                       pooeek !
  1125. plouf   dc.b "Hello world !",13,10,'$'  the marvellous text we want to display
  1126.  
  1127.  
  1128.     Oh god ! Assembling this tiny piece of source code will produce a .COM
  1129. file displaying an odd message with the ugly default DOS font.
  1130.  
  1131.  
  1132.     Here is another version of it, ridiculously longer. But this shows the
  1133. structure of an executable ( .EXE ) program. At least the half of the following
  1134. instructions are dumbshit, but this can help you understand the GEMA's point of
  1135. view on segmentation :
  1136.  
  1137.         header                          create a .EXE and not a .COM
  1138.         overlay $1234                   overlay number ( not very useful here )
  1139.         min 1+@fin                      minimal necessary memory ( implicit )
  1140.         max 1+@fin                      ...equals the max one ( just for fun )
  1141.  
  1142.         move cs,a                       code segment address
  1143.         move a,ds                       ...into ds
  1144.         move.b #9,ah                    fonction 9
  1145.         move #plouf,d                   plouf's offset into DX
  1146.         trap #$21                       call the DOS
  1147.         move #$4c00,a                   return code to the DOS
  1148.         trap #$21                       let's call it
  1149. plouf   dc.b "Hello world !",13,10,'$'  text to be displayed
  1150.  
  1151.         segment                         alignment to a multiple of 16 bytes
  1152.         ds.l 128                        some space for the stack ( 128 Lwords )
  1153. fin     stack                           the new stack starts here
  1154.  
  1155.  
  1156.     If despite this summary you still have troubles using GEMA, please
  1157. report them to me, the faster way being thru e-mail to j@nether.net
  1158.  
  1159.  
  1160. IV. That's all folks
  1161. --------------------
  1162.  
  1163.  
  1164.     I hope you'll be able to use this fabulous ( well... just about ) tool
  1165. and see its advantage to TASM and MASM. All suggestions, critics, remarks and
  1166. bug-reports will be welcomed.
  1167.  
  1168.  
  1169.  
  1170.  
  1171.  
  1172.